package com.ruoyi.bearing.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.bearing.domain.ModelTrain;
import com.ruoyi.bearing.mapper.ModelTrainMapper;
import com.ruoyi.common.enums.TrainState;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bearing.mapper.ModelInfoMangmentMapper;
import com.ruoyi.bearing.domain.ModelInfoMangment;
import com.ruoyi.bearing.service.IModelInfoMangmentService;

/**
 * 模型管理Service业务层处理
 *
 * @author ruoyi
 * @date 2023-07-14
 */
@Service
public class ModelInfoMangmentServiceImpl implements IModelInfoMangmentService {
    @Autowired
    private ModelInfoMangmentMapper modelInfoMangmentMapper;
    @Autowired
    private ModelTrainMapper modelTrainMapper;

    /**
     * 查询模型管理
     *
     * @param mid 模型管理主键
     * @return 模型管理
     */
    @Override
    public ModelInfoMangment selectModelInfoMangmentByMid(String mid) {
        return modelInfoMangmentMapper.selectModelInfoMangmentByMid(mid);
    }

    /**
     * 查询模型管理列表
     *
     * @param modelInfoMangment 模型管理
     * @return 模型管理
     */
    @Override
    public List<ModelInfoMangment> selectModelInfoMangmentList(ModelInfoMangment modelInfoMangment) {
        List<ModelInfoMangment> modelInfoList = modelInfoMangmentMapper.selectModelInfoMangmentList(modelInfoMangment);
        for (int i = 0; i < modelInfoList.size(); i++) {
            if("0".equals(modelInfoList.get(i).getState()) ){
                modelInfoList.get(i).setState(TrainState.Yes.getInfo());
            }
            else{
                modelInfoList.get(i).setState(TrainState.No.getInfo());
            }
        }
        return modelInfoList;
    }

    /**
     * 下载
     * @return
     */
    @Override
    public List<ModelTrain> getModelInfoByMid(ModelInfoMangment modelInfoMangment) {
        String mid = modelInfoMangment.getMid();
        ModelTrain modelTrain = modelTrainMapper.selectModelTrainByMid(mid);
        ModelInfoMangment model = modelInfoMangmentMapper.selectModelInfoMangmentByMid(mid);
        modelTrain.setCreateTime(model.getCreateTime());
        List<ModelTrain> modelInfoList = new ArrayList<>(1);
        modelInfoList.add(modelTrain);
        return modelInfoList;
    }

    /**
     * 新增模型管理
     *
     * @param modelInfoMangment 模型管理
     * @return 结果
     */
    @Override
    public int insertModelInfoMangment(ModelInfoMangment modelInfoMangment) {
        modelInfoMangment.setCreateTime(DateUtils.getNowDate());
        return modelInfoMangmentMapper.insertModelInfoMangment(modelInfoMangment);
    }

    /**
     * 修改模型管理
     *
     * @param modelInfoMangment 模型管理
     * @return 结果
     */
    @Override
    public int updateModelInfoMangment(ModelInfoMangment modelInfoMangment) {
        modelInfoMangment.setUpdateTime(DateUtils.getNowDate());
        return modelInfoMangmentMapper.updateModelInfoMangment(modelInfoMangment);
    }

    /**
     * 批量删除模型管理
     *
     * @param mids 需要删除的模型管理主键
     * @return 结果
     */
    @Override
    public int deleteModelInfoMangmentByMids(String[] mids) {
        modelTrainMapper.deleteModelTrainByMids(mids);
        return modelInfoMangmentMapper.deleteModelInfoMangmentByMids(mids);
    }

    /**
     * 删除模型管理信息
     *
     * @param mid 模型管理主键
     * @return 结果
     */
    @Override
    public int deleteModelInfoMangmentByMid(String mid) {
        return modelInfoMangmentMapper.deleteModelInfoMangmentByMid(mid);
    }
}
